#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
const ll maxn = 2e3+10;
const ll mod = 1e9+7;
const ll INF = 0x3f3f3f3f;
ll d[4][2]={1,0,0,1,-1,0,0,-1};
ll a[maxn];
inline ll read(){
   ll s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    #ifdef Uncle_drew
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #else
    #endif
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int> a(n);
        for(int i=0;i<n;i++)    cin>>a[i];
        int ans=0;
        map<int,int> ma;
        for(int j=n-1;j>=0;j--){
            for(int i=0;i<j;i++){
                int mid=a[j]+a[j]-a[i];
				if (ma.count(mid))
                ans+=ma[mid];
            }
            ma[a[j]]++;
        }
        cout<<ans<<endl;
    }
    return 0;
}
